package com.jh.paymentchannel.service;

//import static org.hamcrest.CoreMatchers.nullValue;
//import static org.junit.Assert.fail;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jh.paymentchannel.pojo.BranchNo;
import com.jh.paymentchannel.pojo.CJQuickBindCard;
import com.jh.paymentchannel.pojo.CJRegister;
import org.apache.commons.lang3.StringUtils;
//import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.TypeReference;
import com.jh.paymentchannel.business.BranchbankBussiness;
import com.jh.paymentchannel.business.TopupPayChannelBusiness;
import com.jh.paymentchannel.util.Util;
import com.jh.paymentchannel.util.cj.BaseResMessage;
import com.jh.paymentchannel.util.cj.Constants;
import com.jh.paymentchannel.util.cj.ConsumeSMSVo;
import com.jh.paymentchannel.util.cj.ConsumeVo;
import com.jh.paymentchannel.util.cj.EncryptUtil;
import com.jh.paymentchannel.util.cj.MerchantVo;
import com.jh.paymentchannel.util.cj.PageOpenCardVo;
import com.jh.paymentchannel.util.cj.PayGetToken;
import com.jh.paymentchannel.util.cj.SignUtil;
import com.jh.paymentchannel.util.cj.TokenConstants;
import com.jh.paymentchannel.util.cj.TokenRes;

import cn.jh.common.utils.DateUtil;
import net.sf.json.JSONObject;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

@Controller
@EnableAutoConfiguration
public class CJQuickpageRequest {

	private static final Logger log = LoggerFactory.getLogger(CJQuickpageRequest.class);

	public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
	@Autowired
	private TopupPayChannelBusiness topupPayChannelBusiness;

	@Autowired
	private BranchbankBussiness branchbankBussiness;

	@Autowired
	private Util util;

	@Value("${payment.ipAddress}")
	private String ipAddress;

	// 服务商编号
	@Value("${cj.org_no}")
	private String serverProviderCode;
	// 服务商秘钥
	@Value("${cj.key}")
	private String Key;

	private String Url = "https://qkapi.chanpay.com";

	private static final Charset UTF_8 = StandardCharsets.UTF_8;

	private String rateCode = "1000002";

	private String capAmount = "999999";

	/**
	 * 进件接口
	 *
	 */
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cjquick/register")
	public @ResponseBody Object jfCoinRegister(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode,
			@RequestParam(value = "provinceOfBank") String provinceOfBank,
			@RequestParam(value = "cityOfBank") String cityOfBank,
			@RequestParam(value = "bankBranchName") String bankBranchName) throws Exception {
		log.info("开始进入CJQuick进件接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String realamount = resultObj.getString("realAmount");
		String userid = resultObj.getString("userid");
		// 费率
		String rate = resultObj.getString("rate");
		// 额外费率
		String extraFee = resultObj.getString("extraFee");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询默认结算卡出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询默认结算卡有误");
			return map;
		}
		String respcode = jsonObject.getString("resp_code");
		if (!"000000".equals(respcode)) {

			maps.put("resp_code", "failed");
			maps.put("channel_type", "jfcoin");
			maps.put("resp_message", "没有结算卡");
			return maps;
		}

		// 默认提现卡卡号
		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");
		String bankName = resultObj.getString("bankName");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/query/randomuserid";
		requestEntity = new LinkedMultiValueMap<String, String>();

		String shopUserId;
		try {
			result = restTemplate.postForObject(url, requestEntity, String.class);
			jsonObject = JSONObject.fromObject(result);
			shopUserId = jsonObject.getString("result");
		} catch (Exception e1) {
			log.error("查询用户ID出错！！！！");
			maps.put("resp_code", "failed");
			maps.put("channel_type", "sdj");
			maps.put("resp_message", "没有查询到用户ID");
			return maps;
		}

		log.info("随机获取的userId" + shopUserId);

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/shops/query/uid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("userid", shopUserId);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询商铺信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询商铺信息有误");
			return map;
		}

		String shopName = resultObj.getString("name");// 商户全称

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
			maps.put("resp_code", "failed");
			maps.put("resp_message", "根据银行名称获取银行编码失败");
			return maps;
		}

		// 银行编号
		String code = jsonObject.getString("result");

		// 根据银行名称查询得到银行信息
		BranchNo findByBankName;
		try {
			findByBankName = branchbankBussiness.findByBankName(bankName);
		} catch (Exception e1) {
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行信息有误");
			return map;
		}
		// 银行总行联行号
		String inBankUnitNo = findByBankName.getBankNo();

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		if (resultObj == null) {
			return null;
		}

		String cardName = resultObj.getString("bankName");

		String cardname = Util.queryBankNameByBranchName(cardName);

		String expiredTime = resultObj.getString("expiredTime");
		String securityCode = resultObj.getString("securityCode");
		String cardType = resultObj.getString("cardType");

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.MERCHANT_REGISTERED_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		String CapAmount = new BigDecimal(capAmount).multiply(new BigDecimal("100")).setScale(0).toString();

		// 将额外费用变成以分为单位
		String ExtraFee = new BigDecimal(extraFee).multiply(new BigDecimal("100")).setScale(0).toString();

		// 敏感数据3DES加密
		String bankAccountNo = null;
		String phoneno = null;
		String idCardNo = null;
		try {
			bankAccountNo = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
			idCardNo = EncryptUtil.desEncrypt(idcard, Key);
		} catch (Exception e) {
			log.error("敏感数据3DES加密出错啦========" + e);
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "敏感数据3DES加密出错啦");
			return map;
		}

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);// 服务商编号
		signParams.put("rateCode", rateCode);// 服务商费率编号
		signParams.put("merName", shopName);// 商户名称
		signParams.put("merAbbr", shopName);// 商户简称
		signParams.put("idCardNo", idcard);// 身份证号
		signParams.put("bankAccountNo", cardNo);// 银行卡卡号
		signParams.put("phoneno", phone);// 银行卡预留手机号
		signParams.put("bankAccountName", userName);// 银行卡户名
		signParams.put("bankAccountType", "2");// 银行卡账户类型 2 对私
		signParams.put("bankName", bankName);// 银行名称
		signParams.put("bankSubName", bankBranchName);// 银行支行名称
		signParams.put("bankCode", code);// 银行代码
		signParams.put("bankAbbr", code);// 银行代号
		signParams.put("bankChannelNo", inBankUnitNo);// 银行联行号
		signParams.put("bankProvince", provinceOfBank);// 银行所属省
		signParams.put("bankCity", cityOfBank);// 银行所属市
		signParams.put("debitRate", rate);// 借记卡费率
		signParams.put("debitCapAmount", CapAmount);// 借记卡封顶
		signParams.put("creditRate", rate);// 信用卡费率
		signParams.put("creditCapAmount", CapAmount);// 信用卡封顶
		signParams.put("withdrawDepositRate", "0");// 提现费率
		signParams.put("withdrawDepositSingleFee", ExtraFee);// 单笔提现手续费

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("rateCode", rateCode);// 服务商费率编号
		jsonObj.put("merName", shopName);// 商户名称
		jsonObj.put("merAbbr", shopName);// 商户简称
		jsonObj.put("idCardNo", idCardNo);// 身份证号
		jsonObj.put("bankAccountNo", bankAccountNo);// 银行卡卡号
		jsonObj.put("phoneno", phoneno);// 银行卡预留手机号
		jsonObj.put("bankAccountName", userName);// 银行卡户名
		jsonObj.put("bankAccountType", "2");// 银行卡账户类型 2 对私
		jsonObj.put("bankName", bankName);// 银行名称
		jsonObj.put("bankSubName", bankBranchName);// 银行支行名称
		jsonObj.put("bankCode", code);// 银行代码
		jsonObj.put("bankAbbr", code);// 银行代号
		jsonObj.put("bankChannelNo", inBankUnitNo);// 银行联行号
		jsonObj.put("bankProvince", provinceOfBank);// 银行所属省
		jsonObj.put("bankCity", cityOfBank);// 银行所属市
		jsonObj.put("debitRate", rate);// 借记卡费率
		jsonObj.put("debitCapAmount", CapAmount);// 借记卡封顶
		jsonObj.put("creditRate", rate);// 信用卡费率
		jsonObj.put("creditCapAmount", CapAmount);// 信用卡封顶
		jsonObj.put("withdrawDepositRate", "0");// 提现费率
		jsonObj.put("withdrawDepositSingleFee", ExtraFee);// 单笔提现手续费
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		client.newBuilder().connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS)
				.writeTimeout(Constants.WRITE_TIMEOUT, TimeUnit.SECONDS)
				.readTimeout(Constants.READ_TIMEOUT, TimeUnit.SECONDS);
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/v1/merchant/merchantReg").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<MerchantVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp, new TypeReference<BaseResMessage<MerchantVo>>() {
			});

			log.info("\n接口响应内容：" + res.getData());
			// code 等于 00 代表进件成功
			if ("00".equals(res.getCode())) {
				log.info("CJQuick用户进件成功==========");
				CJRegister cjRegister = new CJRegister();
				cjRegister.setUserId(Long.parseLong(userid));
				cjRegister.setBankCard(cardNo);
				cjRegister.setCreditRate(rate);
				// cjRegister.setDebitRate(rate);
				cjRegister.setMerchantCode(res.getData().getMerchantCode());
				cjRegister.setMerchantUuid(res.getData().getMerchantUuid());
				cjRegister.setRateCode2(rateCode);
				cjRegister.setServerProviderCode(res.getData().getServerProviderCode());
				cjRegister.setWithrawDepositRate("0.0");
				cjRegister.setWithdrawDepositsingleFee(extraFee);

				topupPayChannelBusiness.createCJRegister(cjRegister);

				map.put("resp_code", "success");
				map.put("channel_type", "jf");
				map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/tocjquickbindcard?bankName="
						+ URLEncoder.encode(cardname, "UTF-8") + "cardType=" + URLEncoder.encode(cardType, "UTF-8")
						+ "&bankCard=" + bankCard + "&ordercode=" + ordercode + "&expiredTime=" + expiredTime
						+ "&securityCode=" + securityCode + "&isRegister=1");
				return map;

			}else {
				log.info("用户进件失败======");
				map.put("resp_code", "failed");
				map.put("channel_type", "jf");
				map.put("resp_message", res.getMessage());
				return map;
			}

		} else {
			log.info("响应码: " + responses.code());
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", responses.message());
			return map;
		}

	}

	// 商户侧开通短信
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cj/opencardsms")
	public @ResponseBody Object OpenCardSMS(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "ordercode") String ordercode) throws Exception {

		log.info("开始进入商户侧开通短信接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String userid = resultObj.getString("userid");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询默认结算卡出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询默认结算卡有误");
			return map;
		}
		String respcode = jsonObject.getString("resp_code");
		if (!"000000".equals(respcode)) {

			maps.put("resp_code", "failed");
			maps.put("channel_type", "jfcoin");
			maps.put("resp_message", "没有结算卡");
			return maps;
		}

		// 通过 userId 查询用户进件信息
		CJRegister cjRegister = topupPayChannelBusiness.getCJRegister(Long.parseLong(userid));
		String merchantCode = cjRegister.getMerchantCode();

		// 查询信用卡信息
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		// 信用卡卡号
		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");
		String bankName = resultObj.getString("bankName");

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
			maps.put("resp_code", "failed");
			maps.put("resp_message", "根据银行名称获取银行编码失败");
			return maps;
		}

		// 银行编号
		String code = jsonObject.getString("result");

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.OPEN_CARD_SMS_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		// 敏感数据3DES加密
		String cardno = null;
		String phoneno = null;
		String certNo = null;
		try {
			cardno = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
			certNo = EncryptUtil.desEncrypt(idcard, Key);
		} catch (Exception e) {
			e.printStackTrace();
		}

		String time = DateUtil.getyyyyMMddHHmmssSSSDateFormat(new Date());
		String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 3);

		String requestId = time + uuid;

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("requestId", requestId);
		signParams.put("orderId", ordercode);
		signParams.put("merchantCode", merchantCode);
		signParams.put("rateCode", rateCode);
		signParams.put("accountName", userName);
		signParams.put("cardNo", cardNo);
		signParams.put("cardType", "2");
		signParams.put("certType", "01");
		signParams.put("certNo", idcard);
		signParams.put("phoneno", phone);
		signParams.put("bankCode", code);
		signParams.put("bankAbbr", code);

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("requestId", requestId);
		jsonObj.put("orderId", ordercode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("rateCode", rateCode);
		jsonObj.put("accountName", userName);
		jsonObj.put("cardNo", cardno);
		jsonObj.put("cardType", "2");
		jsonObj.put("certType", "01");
		jsonObj.put("certNo", certNo);
		jsonObj.put("phoneno", phoneno);
		jsonObj.put("bankCode", code);
		jsonObj.put("bankAbbr", code);
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/gateway/api/openCardSMS").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<PageOpenCardVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp,
					new TypeReference<BaseResMessage<PageOpenCardVo>>() {
					});
			log.info("\n接口响应内容：" + res.getData());
			if ("000000".equals(res.getData().getRespCode())) {
				map.put("resp_code", "success");
				map.put("channel_type", "jf");
				return map;
			}else {
				map.put("resp_code", "failed");
				map.put("channel_type", "jf");
				map.put("resp_message", res.getMessage());
				return map;
			}
			
		} else {
			log.info("响应码: " + responses.code());
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", responses.message());
			return map;
		}
	}

	// 商户侧绑卡接口
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cj/backopencard")
	public @ResponseBody Object backOpenCard(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode, @RequestParam(value = "smsCode") String smsCode,
			@RequestParam(value = "expiredTime", required = false) String expiredTime,
			@RequestParam(value = "securityCode", required = false) String securityCode) throws Exception {

		log.info("开始进入商户侧绑卡接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String userid = resultObj.getString("userid");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询默认结算卡出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询默认结算卡有误");
			return map;
		}
		String respcode = jsonObject.getString("resp_code");
		if (!"000000".equals(respcode)) {

			maps.put("resp_code", "failed");
			maps.put("channel_type", "jfcoin");
			maps.put("resp_message", "没有结算卡");
			return maps;
		}

		// 通过 userId 查询用户进件信息
		CJRegister cjRegisterByRateCode = topupPayChannelBusiness.getCJRegisterByRateCode2(Long.parseLong(userid),
				rateCode);
		String merchantCode = cjRegisterByRateCode.getMerchantCode();

		// 查询信用卡信息
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		if (resultObj == null) {
			return null;
		}
		// 信用卡卡号
		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");
		String bankName = resultObj.getString("bankName");

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
			maps.put("resp_code", "failed");
			maps.put("resp_message", "根据银行名称获取银行编码失败");
			return maps;
		}

		// 银行编号
		String code = jsonObject.getString("result");

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.OPEN_CARD_BACK_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		// 敏感数据3DES加密
		String cardno = null;
		String phoneno = null;
		String certNo = null;
		String cvn2 = null;
		try {
			cardno = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
			certNo = EncryptUtil.desEncrypt(idcard, Key);
			if (StringUtils.isNotEmpty(securityCode))
				cvn2 = EncryptUtil.desEncrypt(securityCode, Key);
		} catch (Exception e) {
			e.printStackTrace();
		}

		String time = DateUtil.getyyyyMMddHHmmssSSSDateFormat(new Date());
		String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 3);

		String requestId = time + uuid;

		/*
		 * if (null != expiredTime && !"".equals(expiredTime)) { expiredTime =
		 * resultObj.getString("expiredTime");
		 * 
		 * String before = expiredTime.substring(0, 2); String after =
		 * expiredTime.substring(2, 4);
		 * 
		 * BigDecimal big = new BigDecimal(before); BigDecimal times = new
		 * BigDecimal("12");
		 * 
		 * int compareTo = big.compareTo(times); // 如果前两位大于12，,代表是年/月的格式 if (compareTo
		 * == 1) { expiredTime = after + before; } log.info("统一格式后的expiredTime========="
		 * + expiredTime); }
		 */

		String before = expiredTime.substring(0, 2);
		String after = expiredTime.substring(2, 4);

		BigDecimal big = new BigDecimal(before);
		BigDecimal times = new BigDecimal("12");

		int compareTo = big.compareTo(times);
		// 如果前两位大于12，,代表是年/月的格式
		if (compareTo == 1) {
			expiredTime = before + after;
		}else {
			expiredTime = after + before;
		}
		
		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("requestId", requestId);
		signParams.put("orderId", ordercode);
		signParams.put("merchantCode", merchantCode);
		signParams.put("rateCode", rateCode);
		signParams.put("accountName", userName);
		signParams.put("cardNo", cardNo);
		signParams.put("cardType", "2");
		signParams.put("certType", "01");
		signParams.put("certNo", idcard);
		signParams.put("phoneno", phone);
		signParams.put("cvn2", securityCode);
		signParams.put("expired", expiredTime);
		signParams.put("bankCode", code);
		signParams.put("bankAbbr", code);
		signParams.put("smsCode", smsCode);

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("requestId", requestId);
		jsonObj.put("orderId", ordercode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("rateCode", rateCode);
		jsonObj.put("accountName", userName);
		jsonObj.put("cardNo", cardno);
		jsonObj.put("cardType", "2");
		jsonObj.put("certType", "01");
		jsonObj.put("certNo", certNo);
		jsonObj.put("phoneno", phoneno);
		jsonObj.put("cvn2", cvn2);
		jsonObj.put("expired", expiredTime);
		jsonObj.put("bankCode", code);
		jsonObj.put("bankAbbr", code);
		jsonObj.put("smsCode", smsCode);
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/gateway/api/backOpenCard").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<PageOpenCardVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp,
					new TypeReference<BaseResMessage<PageOpenCardVo>>() {
					});
			log.info("\n接口响应内容：" + res.getData());
			if ("000000".equals(res.getData().getRespCode()) && "2".equals(res.getData().getActivateStatus())) {

				String ActivateStatus = (String) this.openCardQuery(request, ordercode);
				if ("2".equals(ActivateStatus)) {
					
					CJQuickBindCard cjQuickBindCard = topupPayChannelBusiness.getCJQuickBindCard(userid, bankCard);
					
					if(null == cjQuickBindCard) {
						CJQuickBindCard cjQuickBindCard1 = new CJQuickBindCard();
						cjQuickBindCard1.setUserId(userid);
						cjQuickBindCard1.setBankCard(bankCard);
						try {
							topupPayChannelBusiness.createCJQuickBindCard(cjQuickBindCard1);
						} catch (Exception e) {
							log.error("保存用户绑卡信息失败=====");
							maps.put("resp_code", "failed");
							maps.put("channel_type", "jf");
							maps.put("resp_message", "保存用户绑卡信息失败");
							return maps;
						}
						
						log.info("用户通过商户侧绑卡成功并存入数据库");
					}else {
						cjQuickBindCard.setBankCard(bankCard);
						cjQuickBindCard.setUserId(userid);
						try {
							topupPayChannelBusiness.createCJQuickBindCard(cjQuickBindCard);
						} catch (Exception e) {
							log.error("保存用户绑卡信息失败=====");
							maps.put("resp_code", "failed");
							maps.put("channel_type", "jf");
							maps.put("resp_message", "保存用户绑卡信息失败");
							return maps;
						}
						log.info("用户通过商户侧绑卡成功并存入数据库");
					}
					
				}

				map.put("resp_code", "success");
				map.put("channel_type", "jf");
				map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/cjbindcardsuccess");
				return map;
			} else {
				map.put("resp_code", "failed");
				map.put("channel_type", "jf");
				map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/cjbindcarderror");
				return map;
			}

		} else {
			log.info("响应码: " + responses.code());
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", responses.message());
			return map;
		}

	}

	
	// 支付短信接口
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cjquick/consumesms")
	public @ResponseBody Object consumeSMS(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "ordercode") String ordercode) throws Exception {

		log.info("开始进入支付短信接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String amount = resultObj.getString("amount");
		String userid = resultObj.getString("userid");
		// 费率
		String rate = resultObj.getString("rate");
		// 额外费率
		String extraFee = resultObj.getString("extraFee");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询默认结算卡出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询默认结算卡有误");
			return map;
		}
		String respcode = jsonObject.getString("resp_code");
		if (!"000000".equals(respcode)) {

			maps.put("resp_code", "failed");
			maps.put("channel_type", "jfcoin");
			maps.put("resp_message", "没有结算卡");
			return maps;
		}

		// 通过 userId 查询用户进件信息
		CJRegister cjRegister = topupPayChannelBusiness.getCJRegister(Long.parseLong(userid));
		String merchantCode = cjRegister.getMerchantCode();

		// 查询信用卡信息
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		if (resultObj == null) {
			return null;
		}
		// 信用卡卡号
		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");
		String bankName = resultObj.getString("bankName");

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
			maps.put("resp_code", "failed");
			maps.put("resp_message", "根据银行名称获取银行编码失败");
			return maps;
		}

		// 银行编号
		String code = jsonObject.getString("result");

		// 根据银行名称查询得到银行信息
		BranchNo findByBankName;
		try {
			findByBankName = branchbankBussiness.findByBankName(bankName);
		} catch (Exception e1) {
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行信息有误");
			return map;
		}
		// 银行总行联行号
		String inBankUnitNo = findByBankName.getBankNo();

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.PAY_SMS_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		// 将订单金额变成以分为单位
		String Amount = new BigDecimal(amount).multiply(new BigDecimal("100")).setScale(0).toString();

		// 敏感数据3DES加密
		String orderAmount = null;
		String cardno = null;
		String phoneno = null;
		String certNo = null;
		try {
			orderAmount = EncryptUtil.desEncrypt(Amount, Key);
			cardno = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
			certNo = EncryptUtil.desEncrypt(idcard, Key);
		} catch (Exception e) {
			e.printStackTrace();
		}

		String time = DateUtil.getyyyyMMddHHmmssSSSDateFormat(new Date());
		String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 3);

		String requestId = time + uuid;

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("requestId", requestId);
		signParams.put("orderId", ordercode);
		signParams.put("merchantCode", merchantCode);
		signParams.put("rateCode", rateCode);
		signParams.put("orderAmount", Amount);
		signParams.put("cardNo", cardNo);
		signParams.put("accountName", userName);
		signParams.put("cardType", "2");
		signParams.put("phoneno", phone);
		signParams.put("certType", "01");
		signParams.put("certNo", idcard);
		signParams.put("bankCode", code);
		signParams.put("bankAbbr", code);

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("requestId", requestId);
		jsonObj.put("orderId", ordercode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("rateCode", rateCode);
		jsonObj.put("orderAmount", orderAmount);
		jsonObj.put("cardNo", cardno);
		jsonObj.put("accountName", userName);
		jsonObj.put("cardType", "2");
		jsonObj.put("phoneno", phoneno);
		jsonObj.put("certType", "01");
		jsonObj.put("certNo", certNo);
		jsonObj.put("bankCode", code);
		jsonObj.put("bankAbbr", code);
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/gateway/api/consumeSMS").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<ConsumeSMSVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp,
					new TypeReference<BaseResMessage<ConsumeSMSVo>>() {
					});
			log.info("\n接口响应内容：" + res.getData());

			if ("000000".equals(res.getCode())) {

				String payNo = res.getData().getPayNo();
				map.put("resp_code", "success");
				map.put("channel_type", "jf");
				map.put("pay_no", res.getData().getPayNo());
				return map;
			}else {
				map.put("resp_code", "failed");
				map.put("channel_type", "jf");
				map.put("resp_message", res.getMessage());
				return map;
			}

		} else {
			log.info("响应码: " + responses.code());
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", responses.message());
			return map;
		}

	}

	// 支付接口
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cjquick/consume")
	public @ResponseBody Object cjconsume(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode, @RequestParam(value = "smsCode") String smsCode,
			@RequestParam(value = "payNo") String payNo) throws Exception {

		log.info("开始进入消费支付接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String amount = resultObj.getString("amount");
		String userid = resultObj.getString("userid");
		// 费率
		String rate = resultObj.getString("rate");
		// 额外费率
		String extraFee = resultObj.getString("extraFee");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询默认结算卡出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "查询默认结算卡有误");
			return map;
		}
		String respcode = jsonObject.getString("resp_code");
		if (!"000000".equals(respcode)) {

			maps.put("resp_code", "failed");
			maps.put("channel_type", "jfcoin");
			maps.put("resp_message", "没有结算卡");
			return maps;
		}

		// 通过 userId 查询用户进件信息
		CJRegister cjRegister = null;
		try {
			cjRegister = topupPayChannelBusiness.getCJRegisterByRateCode2(Long.parseLong(userid), rateCode);
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		String merchantCode = cjRegister.getMerchantCode();

		// 查询信用卡信息
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		if (resultObj == null) {
			return null;
		}
		// 信用卡卡号
		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");
		String bankName = resultObj.getString("bankName");

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
			maps.put("resp_code", "failed");
			maps.put("resp_message", "根据银行名称获取银行编码失败");
			return maps;
		}

		// 银行编号
		String code = jsonObject.getString("result");

		// 根据银行名称查询得到银行信息
		BranchNo findByBankName;
		try {
			findByBankName = branchbankBussiness.findByBankName(bankName);
		} catch (Exception e1) {
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行信息有误");
			return map;
		}
		// 银行总行联行号
		String inBankUnitNo = findByBankName.getBankNo();

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.CONSUME_PAY_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		// 将订单金额变成以分为单位
		String Amount = new BigDecimal(amount).multiply(new BigDecimal("100")).setScale(0).toString();

		// 异步通知地址
		String notifyUrl = ipAddress + "/v1.0/paymentchannel/topup/cj/pay_notify_call";

		// 敏感数据3DES加密
		String payAmount = null;
		String cardno = null;
		String phoneno = null;
		String certNo = null;
		String offlineNotifyUrl = null;
		try {
			payAmount = EncryptUtil.desEncrypt(Amount, Key);
			cardno = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
			certNo = EncryptUtil.desEncrypt(idcard, Key);
			offlineNotifyUrl = Base64.getEncoder().encodeToString(EncryptUtil.desEncrypt(notifyUrl, Key).getBytes());
		} catch (Exception e) {
			e.printStackTrace();
		}

		String time = DateUtil.getyyyyMMddHHmmssSSSDateFormat(new Date());
		String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 3);

		String requestId = time + uuid;

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("requestId", requestId);
		signParams.put("orderId", ordercode);
		signParams.put("merchantCode", merchantCode);
		signParams.put("rateCode", rateCode);
		signParams.put("payNo", payNo);
		signParams.put("payAmount", Amount);
		signParams.put("cardNo", cardNo);
		signParams.put("accountName", userName);
		signParams.put("cardType", "2");
		signParams.put("phoneno", phone);
		signParams.put("certType", "01");
		signParams.put("certNo", idcard);
		signParams.put("bankCode", code);
		signParams.put("bankAbbr", code);
		signParams.put("smsCode", smsCode);
		signParams.put("productName", "充值缴费");
		signParams.put("productDesc", "充值缴费");
		signParams.put("offlineNotifyUrl", notifyUrl);

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("requestId", requestId);
		jsonObj.put("orderId", ordercode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("rateCode", rateCode);
		jsonObj.put("payNo", payNo);
		jsonObj.put("payAmount", payAmount);
		jsonObj.put("cardNo", cardno);
		jsonObj.put("accountName", userName);
		jsonObj.put("cardType", "2");
		jsonObj.put("phoneno", phoneno);
		jsonObj.put("certType", "01");
		jsonObj.put("certNo", certNo);
		jsonObj.put("bankCode", code);
		jsonObj.put("bankAbbr", code);
		jsonObj.put("smsCode", smsCode);
		jsonObj.put("productName", "充值缴费");
		jsonObj.put("productDesc", "充值缴费");
		jsonObj.put("offlineNotifyUrl", offlineNotifyUrl);
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/gateway/api/consume").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<ConsumeVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp, new TypeReference<BaseResMessage<ConsumeVo>>() {
			});

			log.info("\n接口响应内容：" + res.getData());
			if ("000000".equals(res.getCode())) {
				if ("000000".equals(res.getData().getRespCode())) {
					map.put("resp_code", "success");
					map.put("channel_type", "jf");
					map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/sdjpaysuccess");
					return map;
				} else {
					map.put("resp_code", "failed");
					map.put("channel_type", "jf");
					map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/sdjpayerror");
					return map;
				}
			}

		} else {
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/sdjpayerror");
			return map;
		}

		return null;
	}

	// 银行卡开通状态查询接口
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cj/opencardquery")
	public @ResponseBody Object openCardQuery(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode) throws Exception {

		log.info("开始进入银行卡开通状态查询接口=======");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String userid = resultObj.getString("userid");

		// 通过 userId 查询用户进件信息
		CJRegister cjRegister = null;
		try {
			cjRegister = topupPayChannelBusiness.getCJRegisterByRateCode2(Long.parseLong(userid), rateCode);
		} catch (Exception e) {
			e.printStackTrace();
		}

		String merchantCode = cjRegister.getMerchantCode();

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.OPEN_CARD_STATUS_QUERY_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		String time = DateUtil.getyyyyMMddHHmmssSSSDateFormat(new Date());
		String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 3);

		String requestId = time + uuid;

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("requestId", requestId);
		signParams.put("orderId", ordercode);
		signParams.put("merchantCode", merchantCode);

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("requestId", requestId);
		jsonObj.put("orderId", ordercode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/gateway/api/openCardQuery").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		BaseResMessage<PageOpenCardVo> res = null;
		if (responses.isSuccessful()) {
			res = com.alibaba.fastjson.JSONObject.parseObject(jsonRsp,
					new TypeReference<BaseResMessage<PageOpenCardVo>>() {
					});

			log.info("\n接口响应内容：" + res.getData());

			if ("000000".equals(res.getCode())) {
				return res.getData().getActivateStatus();
			}
		} else {
			log.info("响应码: " + responses.code());
			throw new IOException("Unexpected code " + responses.message());
		}

		return null;
	}

	// 结算卡变更接口
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cjquick/updatecard")
	public @ResponseBody Object updateCard(HttpServletRequest request,

			@RequestParam(value = "ordercode") String ordercode,
			@RequestParam(value = "provinceOfBank") String provinceOfBank,
			@RequestParam(value = "cityOfBank") String cityOfBank,
			@RequestParam(value = "bankBranchName") String bankBranchName) throws Exception {

		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject = JSONObject.fromObject(result);
		JSONObject resultObj = jsonObject.getJSONObject("result");

		String userid = resultObj.getString("userid");

		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/userid";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("user_id", userid);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		jsonObject = JSONObject.fromObject(result);
		resultObj = jsonObject.getJSONObject("result");

		String cardNo = resultObj.getString("cardNo");
		String userName = resultObj.getString("userName");
		/** 身份证号 */
		String idcard = resultObj.getString("idcard");
		String phone = resultObj.getString("phone");

		System.out.println("provinceOfBank" + provinceOfBank);

		System.out.println("cityOfBank" + cityOfBank);
		// 银行名称
		String bankName = resultObj.getString("bankName");

		String cardType = resultObj.getString("cardType");

		// 通过 userId 查询用户进件信息
		CJRegister cjRegister = null;
		try {
			cjRegister = topupPayChannelBusiness.getCJRegisterByRateCode2(Long.parseLong(userid), rateCode);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if (bankName.contains("邮")) {
			bankName = "中国邮政";
		} else if (bankName.contains("浦")) {
			bankName = "浦发银行";
		}
		
		// 根据银行名称获取银行编码
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bankcode/getcodebyname";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("name", bankName);
		result = restTemplate.postForObject(url, requestEntity, String.class);

		log.info("RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
		} catch (Exception e) {
			log.error("根据银行名称获取银行编码失败");
		}

		// 银行编号
		String code = jsonObject.getString("result");

		String merchantCode = cjRegister.getMerchantCode();

		// 根据银行名称查询得到银行信息
		BranchNo findByBankName;
		try {
			findByBankName = branchbankBussiness.findByBankName(bankName);
		} catch (Exception e1) {
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行信息有误");
			return map;
		}
		// 银行总行联行号
		String inBankUnitNo = findByBankName.getBankNo();

		// 获取令牌
		BaseResMessage<TokenRes> tokenRes = new PayGetToken().token(Key, TokenConstants.MERCHANT_CHANGE_TOKEN,
				serverProviderCode);
		String token = tokenRes.getData().getToken();
		// 解密令牌
		String tokenText = EncryptUtil.desDecrypt(token, Key);

		// 敏感数据3DES加密
		String bankAccountNo = null;
		String phoneno = null;
		try {
			bankAccountNo = EncryptUtil.desEncrypt(cardNo, Key);
			phoneno = EncryptUtil.desEncrypt(phone, Key);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 构建签名参数
		TreeMap<String, Object> signParams = new TreeMap<String, Object>();
		signParams.put("token", tokenText);
		signParams.put("serverProviderCode", serverProviderCode);
		signParams.put("merchantCode", merchantCode);
		signParams.put("changeType", "2");
		signParams.put("bankAccountNo", cardNo);
		signParams.put("phoneno", phone);
		signParams.put("bankName", bankName);
		signParams.put("bankSubName", bankBranchName);
		signParams.put("bankCode", code);
		signParams.put("bankAbbr", code);
		signParams.put("bankChannelNo", inBankUnitNo);
		signParams.put("bankProvince", provinceOfBank);
		signParams.put("bankCity", cityOfBank);
		signParams.put("rateCode", rateCode);
		signParams.put("debitRate", "");
		signParams.put("debitCapAmount", "");
		signParams.put("creditRate", "");
		signParams.put("creditCapAmount", "");
		signParams.put("withdrawDepositRate", "");
		signParams.put("withdrawDepositSingleFee", "");

		// 构建请求参数
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("token", tokenText);
		jsonObj.put("serverProviderCode", serverProviderCode);
		jsonObj.put("merchantCode", merchantCode);
		jsonObj.put("changeType", "2");
		jsonObj.put("bankAccountNo", bankAccountNo);
		jsonObj.put("phoneno", phoneno);
		jsonObj.put("bankName", bankName);
		jsonObj.put("bankSubName", bankBranchName);
		jsonObj.put("bankCode", code);
		jsonObj.put("bankAbbr", code);
		jsonObj.put("bankChannelNo", inBankUnitNo);
		jsonObj.put("bankProvince", provinceOfBank);
		jsonObj.put("bankCity", cityOfBank);
		jsonObj.put("rateCode", rateCode);
		jsonObj.put("debitRate", "");
		jsonObj.put("debitCapAmount", "");
		jsonObj.put("creditRate", "");
		jsonObj.put("creditCapAmount", "");
		jsonObj.put("withdrawDepositRate", "");
		jsonObj.put("withdrawDepositSingleFee", "");
		jsonObj.put("sign", SignUtil.signByMap(Key, signParams));

		// 接口访问
		String jsonReq = jsonObj.toString();
		log.info("jsonReq: " + jsonReq);

		OkHttpClient client = new OkHttpClient();
		client.newBuilder().connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS)
				.writeTimeout(Constants.WRITE_TIMEOUT, TimeUnit.SECONDS)
				.readTimeout(Constants.READ_TIMEOUT, TimeUnit.SECONDS);
		RequestBody body = RequestBody.create(JSON, jsonReq);
		Request requests = new Request.Builder().url(Url + "/v1/merchant/merchantChange").post(body).build();
		Response responses = client.newCall(requests).execute();

		String jsonRsp = responses.body().string();
		log.info("jsonRsp: " + jsonRsp);

		boolean istrue = false;
		if (responses.isSuccessful()) {
			log.info("\n接口响应内容：" + jsonRsp);

			CJRegister cjRegisterByRateCode = topupPayChannelBusiness.getCJRegisterByRateCode2(Long.parseLong(userid),
					rateCode);
			cjRegisterByRateCode.setBankCard(cardNo);

			topupPayChannelBusiness.createCJRegister(cjRegisterByRateCode);

			map.put("resp_code", "success");
			map.put("channel_type", "jf");
			map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/cjquickpay?ordercode=" + ordercode);
			return map;

		} else {
			log.info("响应码: " + responses.code());
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", responses.message());
			return map;
		}
	}

	// 用于页面请求跳转的接口=======================================
	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cj/turntobindcardpage")
	public @ResponseBody Object turnToPage(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode) throws Exception {

		log.info("开始进入用于页面请求跳转接口========================");
		Map map = new HashMap();
		Map<String, String> maps = new HashMap<String, String>();
		RestTemplate restTemplate = new RestTemplate();
		URI uri = util.getServiceUrl("transactionclear", "error url request!");
		String url = uri.toString() + "/v1.0/transactionclear/payment/query/ordercode";
		MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("order_code", ordercode);
		String result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("RESULT================" + result);
		JSONObject jsonObject;
		JSONObject resultObj;
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e1) {
			log.error("查询订单信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jfcoin");
			map.put("resp_message", "没有该订单信息");
			return map;
		}

		String userid = resultObj.getString("userid");
		// 充值卡卡号
		String bankCard = resultObj.getString("bankcard");

		// 查询信用卡信息
		restTemplate = new RestTemplate();
		uri = util.getServiceUrl("user", "error url request!");
		url = uri.toString() + "/v1.0/user/bank/default/cardno";
		requestEntity = new LinkedMultiValueMap<String, String>();
		requestEntity.add("cardno", bankCard);
		requestEntity.add("type", "0");
		result = restTemplate.postForObject(url, requestEntity, String.class);
		log.info("接口/v1.0/user/bank/default/cardno--RESULT================" + result);
		try {
			jsonObject = JSONObject.fromObject(result);
			resultObj = jsonObject.getJSONObject("result");
		} catch (Exception e) {
			log.error("查询银行卡信息出错");
			map.put("resp_code", "failed");
			map.put("channel_type", "jf");
			map.put("resp_message", "查询银行卡信息有误");
			return map;
		}
		if (resultObj == null) {
			return null;
		}

		String cardName = resultObj.getString("bankName");
		String expiredTime = resultObj.getString("expiredTime");

		String securityCode = resultObj.getString("securityCode");

		String cardtype = resultObj.getString("cardType");

		String cardname = Util.queryBankNameByBranchName(cardName);

		map.put("resp_code", "success");
		map.put("channel_type", "jf");
		map.put("redirect_url",
				ipAddress + "/v1.0/paymentchannel/topup/tocjquickbindcard?bankName="
						+ URLEncoder.encode(cardname, "UTF-8") + "&cardType=" + URLEncoder.encode(cardtype, "UTF-8")
						+ "&bankCard=" + bankCard + "&ordercode=" + ordercode + "&expiredTime=" + expiredTime
						+ "&securityCode=" + securityCode);
		return map;

	}

	// ========================

	@RequestMapping(method = RequestMethod.POST, value = "/v1.0/paymentchannel/topup/cj/turntocjquickpaypage")
	public @ResponseBody Object turnToCJPayPage(HttpServletRequest request,
			@RequestParam(value = "ordercode") String ordercode) throws Exception {

		Map map = new HashMap();

		map.put("resp_code", "success");
		map.put("channel_type", "jf");
		map.put("redirect_url", ipAddress + "/v1.0/paymentchannel/topup/cjquickpay?&ordercode=" + ordercode);
		return map;

	}

	// 中转接口
	@RequestMapping(method = RequestMethod.GET, value = "/v1.0/paymentchannel/topup/cjquickpay")
	public String returnjfapipay(HttpServletRequest request, HttpServletResponse response, Model model)
			throws IOException {
		// 设置编码
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");

		String ordercode = request.getParameter("ordercode");

		model.addAttribute("ordercode", ordercode);

		return "cjquickpaymessage";
	}

	// 跳转确认提现卡页面的中转接口
	@RequestMapping(method = RequestMethod.GET, value = "/v1.0/paymentchannel/topup/tocjquickbankinfo")
	public String tojfcoinbankinfo(HttpServletRequest request, HttpServletResponse response, Model model)
			throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		log.info("/v1.0/paymentchannel/topup/tojfcoinbankinfo=========tojfcoinbankinfo");
		String bankName = request.getParameter("bankName");// 结算卡银行名称
		String bankNo = request.getParameter("bankNo");// 结算卡卡号
		String amount = request.getParameter("amount");
		String ordercode = request.getParameter("ordercode");
		String provinceOfBank = request.getParameter("provinceOfBank");
		String cityOfBank = request.getParameter("cityOfBank");
		String bankBranchName = request.getParameter("bankBranchName");
		String bankBranchId = request.getParameter("bankBranchId");
		String cardType = request.getParameter("cardType");// 结算卡的卡类型
		String isRegister = request.getParameter("isRegister");
		String cardtype = request.getParameter("cardtype");// 信用卡的卡类型
		String bankCard = request.getParameter("bankCard");// 充值卡卡号
		String cardName = request.getParameter("cardName");// 充值卡银行名称
		String expiredTime = request.getParameter("expiredTime");// 充值卡银行名称
		String securityCode = request.getParameter("securityCode");// 充值卡银行名称

		model.addAttribute("bankName", bankName);
		model.addAttribute("bankNo", bankNo);
		model.addAttribute("amount", amount);
		model.addAttribute("ordercode", ordercode);
		model.addAttribute("provinceOfBank", provinceOfBank);
		model.addAttribute("cityOfBank", cityOfBank);
		model.addAttribute("bankBranchName", bankBranchName);
		model.addAttribute("bankBranchId", bankBranchId);
		model.addAttribute("cardType", cardType);
		model.addAttribute("isRegister", isRegister);
		model.addAttribute("cardtype", cardtype);
		model.addAttribute("bankCard", bankCard);
		model.addAttribute("cardName", cardName);
		model.addAttribute("expiredTime", expiredTime);
		model.addAttribute("securityCode", securityCode);

		return "cjquickbankInfo";
	}

	// 跳转确认绑信用卡页面的中转接口
	@RequestMapping(method = RequestMethod.GET, value = "/v1.0/paymentchannel/topup/tocjquickbindcard")
	public String tocjbindcard(HttpServletRequest request, HttpServletResponse response, Model model)
			throws IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		log.info("/v1.0/paymentchannel/topup/tocjbindcard=========tocjbindcard");
		String cardname = request.getParameter("bankName");// 信用卡银行名称
		String ordercode = request.getParameter("ordercode");
		String cardType = request.getParameter("cardType");
		// String isRegister = request.getParameter("isRegister");
		String bankCard = request.getParameter("bankCard");// 充值卡卡号
		String expiredTime = request.getParameter("expiredTime");// 充值卡卡号
		String securityCode = request.getParameter("securityCode");// 充值卡卡号

		model.addAttribute("bankName", cardname);
		model.addAttribute("ordercode", ordercode);
		model.addAttribute("cardType", cardType);
		// model.addAttribute("isRegister", isRegister);
		model.addAttribute("bankCard", bankCard);
		model.addAttribute("expiredTime", expiredTime);
		model.addAttribute("securityCode", securityCode);

		return "cjquickbindcard";
	}

}